<template>
	<div class="box">
		<view class="nav">
			<navigator open-type="navigateBack" class="back">
				<image src="../../static/img/fanhui.png" mode=""></image>
			</navigator>
			<view class="ops">
				<text class="hot active">动态正文</text>
			</view>
			
			<view class="build" @click="toOk">发布</view>
		</view>
		
		<view class="form">
			<view class="item tt">
				<input type="text" value="" placeholder="请输入项目标题"  v-model="title"/>
			</view>
			
			<view class="item sketch">
				<textarea value="" placeholder="请输入项目详情"  v-model="details"/>
				<view class="addImg">
					<image :src="init0" mode="" @click="addImg(0)"></image>
				</view>
			</view>
			
			<view class="item goal">
				<textarea value="" placeholder="请输入项目目的" />
				<view class="addImg">
					<image :src="init1" mode="" v-model="goal" @click="addImg(1)"></image>
				</view>
			</view>
		</view>
		
	<!-- 	<view class="location">
			<image src="../../static/img/temp.png" mode=""></image>
			<text>添加定位</text>
		</view> -->
	</div>
</template>

<script>
	export default {
		data () {
			return {
				details: "",
				goal: "",
				title: "",
				dbacks: [],
				pbacks: [],
				init0: "../../static/img/jiahao-copy.png",
				init1: "../../static/img/jiahao-copy.png"
			}
		},
		methods: {
			async toOk () {
				let res = await uni.request({
					url: this.$config.basisIP,
					method: "POST",
					data: {
						fun: "public_obj_show",
						community_id: 1,
						details: this.details,
						goal: this.goal,
						title: this.title,
						background: this.init1,
						details_img: this.init0,
						purpose_img: this.init1,
						username: this.$store.state.userInfo.username
					},
					header: {
						"content-type": "application/x-www-form-urlencoded"
					}
				})
				
				res = res[1].data
				
				uni.showToast({
					title: res.result,
					image: "../../static/img/tubiao8-.png"
				})
				
				if (res.code === 200) {
					setTimeout(function () {
						uni.navigateTo({
							url: `../index/itemi?pro_id=${res.result.pro_id}`
						})
					}, 1500)
				}
				
				// uni.navigateTo({
				// 	url: "../index/itemi"
				// })
			},
			async addImg (state) {
				let that = this
				uni.chooseImage({
				    count: 1,
				    async success(res) {
						if (res.tempFilePaths.length > 0) {
						    let filePath = res.tempFilePaths[0]
						    //进行上传操作
							uni.uploadFile({
								url: that.$config.basisIP,
								filePath,
								name: "img",
								formData: {
									fun: "user_upload_img"
								},
								success (res) {
									res = JSON.parse(res.data)
									console.log(res)
									if (res.code === 200) {
										
										if (state) {
											that.init1 = res.result.pur_img
										} else {
											that.init0 = res.result.pur_img
										}
									}
								}
							})
						}
					}
				})
			
			}
		}
	}
</script>

<style lang="scss">
.box {
	.nav {
		padding: 80rpx 22rpx 40rpx;
		display: flex;
		justify-content: center;
		
		.back {
			width: 109rpx;
			height: 37rpx;
			image {
				width: 37rpx;
				height: 100%;
			}
		}
		
		.ops {
			flex: 1;
			text-align: center;
		}
		
		.build {
			width: 109rpx;
			height: 63rpx;
			line-height: 63rpx;
			text-align: center;
			font-size: $middleFont;
			color: #fff;
			border-radius: 90rpx;
			background-color: $yellow;
		}
	}
	
	.form {
		padding: $smallPad;
		
		.item {
			width: 683rpx;
			height: 420rpx;
			background-color: #fff;
			box-shadow: $viewShadow;
			margin-bottom: 50rpx;
			
			textarea {
				box-sizing: border-box;
				width: 100%;
				height: 66%;
				padding: 18rpx;
			}
			
			.addImg {
				height: 34%;
				box-sizing: border-box;
				padding: 0 18rpx 18rpx;
				
				& > image {
					width: 127rpx;
					height: 100%;
					border-radius: 10rpx;
				}
			}
		}
		
		.tt {
			height: auto !important;
		}
	}
	
	.location {
		margin-left: 22rpx;
		width: 192rpx;
		height: 42rpx;
		background: #EDEDED;
		border-radius: 92rpx;
		display: flex;
		justify-content: center;
		
		text {
			margin-left: $smallMargin;
			font-size: $smallFont;
			color: $subColor;
		}
		
		image {
			width: $smallIcon;
			height: $smallIcon;
		}
	}
}
</style>
